package com.huatai.common.httputil;

/**
 * @program: ht-system
 * @description:
 * @author: songxiude
 * @create: 2023-04-25 15:48
 **/

import java.io.IOException;
import javax.annotation.ParametersAreNonnullByDefault;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.Response;

@ParametersAreNonnullByDefault
public class AsyncCallback implements Callback {
	private final AsyncCall asyncCall;

	AsyncCallback(AsyncCall asyncCall) {
		this.asyncCall = asyncCall;
	}

	public void onFailure(Call call, IOException e) {
		this.asyncCall.onFailure(call.request(), e);
	}

	public void onResponse(Call call, Response response) throws IOException {
		HttpResponse httpResponse = new HttpResponse(response);
		Throwable var4 = null;

		try {
			this.asyncCall.onResponse(httpResponse);
			if (response.isSuccessful()) {
				this.asyncCall.onSuccessful(httpResponse);
			} else {
				this.asyncCall.onFailure(call.request(), new IOException(httpResponse.message()));
			}
		} catch (Throwable var13) {
			var4 = var13;
			throw var13;
		} finally {
			if (httpResponse != null) {
				if (var4 != null) {
					try {
						httpResponse.close();
					} catch (Throwable var12) {
						var4.addSuppressed(var12);
					}
				} else {
					httpResponse.close();
				}
			}

		}

	}
}

